<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <title>Duck Hunting Game</title>
    <style>
        body {
            margin: 0;
            overflow: hidden;
            background-color: #87CEEB;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            touch-action: none;
        }
        canvas {
            border: 1px solid #000;
            background-color: #1E90FF;
            max-width: 100%;
            max-height: 100vh;
        }
        #mobileControls {
            position: fixed;
            bottom: 20px;
            left: 50%;
            transform: translateX(-50%);
            display: none;
            gap: 20px;
            z-index: 1000;
        }
        .mobileBtn {
            padding: 15px 30px;
            font-size: 20px;
            background: rgba(255, 255, 255, 0.8);
            border: none;
            border-radius: 25px;
            color: #333;
            touch-action: manipulation;
        }
        #orientation-message {
            position: fixed;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background: rgba(0, 0, 0, 0.8);
            color: white;
            display: none;
            justify-content: center;
            align-items: center;
            z-index: 2000;
            font-size: 1.2rem;
            text-align: center;
            padding: 20px;
        }
        @media (orientation: portrait) {
            #orientation-message {
                display: flex;
            }
        }
        @media (max-width: 768px) {
            #mobileControls {
                display: flex;
            }
        }
    </style>
</head>
<body>
    <div id="orientation-message">
        📱 请旋转设备到横屏模式以获得最佳游戏体验
    </div>
    <canvas id="gameCanvas"></canvas>
    <div id="mobileControls">
        <button class="mobileBtn" id="reloadBtn">装弹 (R)</button>
    </div>
    
    <script>
        const canvas = document.getElementById('gameCanvas');
        const ctx = canvas.getContext('2d');

        // Set canvas size
        canvas.width = 800;
        canvas.height = 600;

        // Game variables
        let score = 0;
        let birds = [];  // 改名为birds以适应多种鸟类
        let lastBirdTime = 0;
        let gunPosition = { x: canvas.width / 2, y: canvas.height - 50 };
        let bullets = 10;
        const maxBullets = 10;
        let reloading = false;
        let activeBullets = [];
        
        // 添加鱼群和水草变量
        let fishes = [];
        let waterWeeds = [];
        
        // 游戏手柄变量
        let gamepad = null;
        let gamepadConnected = false;
        let lastShootTime = 0;
        let shootCooldown = 300; // 射击冷却时间(毫秒)
        let lastReloadTime = 0;
        let reloadCooldown = 500; // 装弹冷却时间(毫秒)
        let gamepadSensitivity = 5; // 手柄灵敏度

        // Bird types configuration
        const BIRD_TYPES = {
            DUCK: {
                color: '#8B4513',
                size: { width: 30, height: 20 },
                speed: { min: 1, max: 2 },
                points: 10,
                flightPattern: 'water_jump',
                shape: 'duck',
                wingSpeed: 0.12
            },
            MALLARD: {
                color: '#556B2F',
                size: { width: 35, height: 22 },
                speed: { min: 1.5, max: 2.5 },
                points: 15,
                flightPattern: 'low_arc',
                shape: 'mallard',
                wingSpeed: 0.15
            },
            TEAL: {
                color: '#20B2AA',
                size: { width: 25, height: 18 },
                speed: { min: 2, max: 3 },
                points: 20,
                flightPattern: 'zigzag',
                shape: 'teal',
                wingSpeed: 0.18
            },
            GOOSE: {
                color: '#696969',
                size: { width: 40, height: 25 },
                speed: { min: 1, max: 1.5 },
                points: 25,
                flightPattern: 'straight_line',
                shape: 'goose',
                wingSpeed: 0.1
            },
            SPARROW: {
                color: '#8B7355',
                size: { width: 20, height: 15 },
                speed: { min: 2.5, max: 3.5 },
                points: 30,
                flightPattern: 'quick_arc',
                shape: 'sparrow',
                wingSpeed: 0.25
            }
        };

        // Sound system
        const SoundSystem = {
            enabled: true,
            audioContext: null,

            init() {
                try {
                    this.audioContext = new (window.AudioContext || window.webkitAudioContext)();
                } catch (e) {
                    console.error('创建音频上下文失败:', e);
                    return;
                }
            },

            play(soundKey) {
                if (!this.enabled || !this.audioContext) return;

                const osc = this.audioContext.createOscillator();
                const gain = this.audioContext.createGain();
                
                switch(soundKey) {
                    case 'SHOOT':
                        osc.frequency.value = 100;
                        gain.gain.value = 0.7;
                        break;
                    case 'DUCK':
                        osc.frequency.value = 200;
                        gain.gain.value = 0.5;
                        break;
                    case 'RELOAD':
                        osc.frequency.value = 400;
                        gain.gain.value = 0.6;
                        break;
                    case 'SPLASH':
                        osc.frequency.value = 300;
                        gain.gain.value = 0.8;
                        break;
                }

                osc.connect(gain);
                gain.connect(this.audioContext.destination);
                
                osc.start();
                setTimeout(() => osc.stop(), 100);
            }
        };

        // 初始化音效系统
        SoundSystem.init();

        // Bird class
        class Bird {
            constructor(type) {
                this.type = type;
                this.config = BIRD_TYPES[type];
                this.resetPosition();
                this.isShot = false;
                this.wingAngle = 0;
                this.wingDirection = 1;
                this.time = 0;
                this.jumpPhase = 0;
                this.visible = this.config.flightPattern !== 'water_jump';
                this.wingOffset = Math.random() * Math.PI;
                // 添加掉落相关属性
                this.fallSpeed = 0;
                this.rotationAngle = 0;
                this.rotationSpeed = 0;
                this.hasSplashed = false;
                this.splashes = [];  // 添加水花数组
                this.rippleTime = 0; // 用于涟漪动画
            }

            resetPosition() {
                switch(this.config.flightPattern) {
                    case 'water_jump':
                        // 从水面跳出
                        this.x = Math.random() * (canvas.width * 0.6) + canvas.width * 0.2;
                        this.y = canvas.height - 200; // 水面位置
                        this.startX = this.x;
                        this.startY = this.y;
                        break;
                    case 'straight_line':
                        // 大雁从侧面飞过
                        this.x = -50;
                        this.y = Math.random() * 200 + 100;
                        this.speedX = this.config.speed.min;
                        break;
                    case 'low_arc':
                        // 低空弧线飞行
                        this.x = Math.random() < 0.5 ? -30 : canvas.width + 30;
                        this.y = canvas.height - 150;
                        this.speedX = (this.x < 0 ? 1 : -1) * 
                            (Math.random() * (this.config.speed.max - this.config.speed.min) + this.config.speed.min);
                        this.speedY = -3;
                        break;
                    default:
                        // 其他鸟类从草丛中出现
                        this.x = Math.random() * canvas.width;
                        this.y = canvas.height - 100;
                        this.speedX = (Math.random() * (this.config.speed.max - this.config.speed.min) + 
                            this.config.speed.min) * (Math.random() < 0.5 ? 1 : -1);
                        this.speedY = -4;
                }
                this.width = this.config.size.width;
                this.height = this.config.size.height;
            }

            update() {
                this.time += 0.02;

                if (this.isShot) {
                    // 初始化掉落参数
                    if (!this.fallSpeed) {
                        this.fallSpeed = -2;
                        this.rotationSpeed = (Math.random() - 0.5) * 0.2;
                    }

                    // 更新掉落位置和旋转
                    this.y += this.fallSpeed;
                    this.fallSpeed += 0.2;
                    this.rotationAngle += this.rotationSpeed;

                    // 检查是否落水
                    if (this.y >= canvas.height - 200 && !this.hasSplashed) {
                        this.hasSplashed = true;
                        this.createSplash();
                    }

                    // 更新水花效果
                    if (this.hasSplashed) {
                        this.updateSplashes();
                        this.rippleTime += 0.02;
                    }

                    return;
                }
                
                // 原有的飞行逻辑
                switch(this.config.flightPattern) {
                    case 'water_jump':
                        if (!this.visible && Math.random() < 0.01) {
                            this.visible = true;
                        }
                        if (this.visible) {
                            this.jumpPhase += 0.03;
                            this.x = this.startX + this.jumpPhase * 30;
                            this.y = this.startY - Math.sin(this.jumpPhase * Math.PI) * 80;
                            if (this.jumpPhase >= 1) {
                                this.config.flightPattern = 'zigzag';
                                this.speedX = 1.5;
                                this.speedY = -1.5;
                            }
                        }
                        break;
                    case 'straight_line':
                        this.x += this.speedX;
                        break;
                    case 'low_arc':
                        this.x += this.speedX;
                        this.y += this.speedY;
                        this.speedY += 0.02;
                        break;
                    case 'quick_arc':
                        this.x += this.speedX;
                        this.y += this.speedY;
                        this.speedY += 0.03;
                        break;
                    case 'zigzag':
                        this.x = this.startX + Math.sin(this.time) * 50;
                        this.y += this.speedY;
                        this.speedY += 0.02;
                        break;
                }

                this.wingAngle = Math.sin(this.time * this.config.wingSpeed * Math.PI * 2 + this.wingOffset) * 0.4;
            }

            createSplash() {
                SoundSystem.play('SPLASH');
                // 创建更多更自然的水花粒子
                const splashCount = 20;
                const waterLevel = canvas.height - 200;
                
                // 主水柱
                for (let i = 0; i < 8; i++) {
                    const angle = (i / 8) * Math.PI * 2;
                    const speed = 3 + Math.random() * 3;
                    this.splashes.push({
                        x: this.x,
                        y: waterLevel,
                        speedX: Math.cos(angle) * speed * 0.7,
                        speedY: Math.sin(angle) * speed - 4,
                        size: 4 + Math.random() * 3,
                        alpha: 1,
                        gravity: 0.2,
                        type: 'column'
                    });
                }
                
                // 水面飞溅
                for (let i = 0; i < splashCount; i++) {
                    const angle = Math.random() * Math.PI * 2;
                    const distance = Math.random() * 40 + 10;
                    const speed = 1 + Math.random() * 2;
                    
                    this.splashes.push({
                        x: this.x + Math.cos(angle) * (Math.random() * 10),
                        y: waterLevel,
                        targetX: this.x + Math.cos(angle) * distance,
                        targetY: waterLevel - Math.random() * 10,
                        progress: 0,
                        speed: 0.01 + Math.random() * 0.02,
                        size: 1 + Math.random() * 2,
                        alpha: 0.7 + Math.random() * 0.3,
                        type: 'splash'
                    });
                }
                
                // 水滴
                for (let i = 0; i < 15; i++) {
                    const angle = (Math.random() * 0.5 + 0.25) * Math.PI;
                    const speed = 2 + Math.random() * 4;
                    
                    this.splashes.push({
                        x: this.x + (Math.random() - 0.5) * 20,
                        y: waterLevel,
                        speedX: Math.cos(angle) * speed,
                        speedY: Math.sin(angle) * speed - 6,
                        size: 1 + Math.random() * 1.5,
                        alpha: 0.8 + Math.random() * 0.2,
                        gravity: 0.25,
                        type: 'droplet',
                        lifetime: 0
                    });
                }
                
                // 添加波纹初始参数
                this.ripples = [];
                for (let i = 0; i < 3; i++) {
                    this.ripples.push({
                        x: this.x + (Math.random() - 0.5) * 30,
                        y: waterLevel,
                        radius: 5 + Math.random() * 5,
                        maxRadius: 30 + Math.random() * 40,
                        alpha: 0.7 + Math.random() * 0.3,
                        speed: 0.5 + Math.random() * 0.5
                    });
                }
            }

            updateSplashes() {
                // 更新水花粒子
                for (let i = this.splashes.length - 1; i >= 0; i--) {
                    const splash = this.splashes[i];
                    
                    if (splash.type === 'column' || splash.type === 'droplet') {
                        // 水柱和水滴使用抛物线运动
                        splash.x += splash.speedX;
                        splash.y += splash.speedY;
                        splash.speedY += splash.gravity;
                        
                        // 水滴碰到水面时产生小波纹
                        if (splash.type === 'droplet') {
                            splash.lifetime += 0.02;
                            if (splash.y >= canvas.height - 200 && splash.speedY > 0) {
                                splash.speedY = -splash.speedY * 0.2;
                                splash.speedX *= 0.8;
                                splash.size *= 0.8;
                                
                                // 偶尔产生二次小波纹
                                if (Math.random() < 0.3 && this.ripples.length < 8) {
                                    this.ripples.push({
                                        x: splash.x,
                                        y: canvas.height - 200,
                                        radius: 2,
                                        maxRadius: 10 + Math.random() * 15,
                                        alpha: 0.5,
                                        speed: 0.4 + Math.random() * 0.3
                                    });
                                }
                            }
                            
                            // 水滴存在时间限制
                            if (splash.lifetime > 2) {
                                splash.alpha -= 0.05;
                            }
                        } else {
                            splash.alpha -= 0.02;
                        }
                    } else if (splash.type === 'splash') {
                        // 水面飞溅使用贝塞尔曲线运动
                        splash.progress += splash.speed;
                        if (splash.progress > 1) {
                            splash.alpha -= 0.1;
                        } else {
                            // 二次贝塞尔曲线模拟飞溅轨迹
                            const t = splash.progress;
                            const u = 1 - t;
                            const controlX = (splash.x + splash.targetX) / 2;
                            const controlY = Math.min(splash.y, splash.targetY) - 20 - Math.random() * 10;
                            
                            splash.currentX = u * u * splash.x + 2 * u * t * controlX + t * t * splash.targetX;
                            splash.currentY = u * u * splash.y + 2 * u * t * controlY + t * t * splash.targetY;
                        }
                    }
                    
                    if (splash.alpha <= 0) {
                        this.splashes.splice(i, 1);
                    }
                }
                
                // 更新波纹
                for (let i = this.ripples.length - 1; i >= 0; i--) {
                    const ripple = this.ripples[i];
                    ripple.radius += ripple.speed;
                    ripple.alpha -= ripple.speed * 0.03;
                    
                    if (ripple.alpha <= 0 || ripple.radius >= ripple.maxRadius) {
                        this.ripples.splice(i, 1);
                    }
                }
            }

            draw() {
                if (!this.visible) return;

                // 绘制水花效果
                if (this.hasSplashed) {
                    this.drawSplashEffects();
                }

                ctx.save();
                ctx.translate(this.x, this.y);
                
                if (this.isShot) {
                    ctx.rotate(this.rotationAngle);
                    if (this.hasSplashed) {
                        ctx.globalAlpha = 0.7;
                    }
                } else {
                    ctx.fillStyle = this.config.color;
                    if (this.speedX < 0) {
                        ctx.scale(-1, 1);
                    }
                }

                // 根据不同鸟类绘制不同形状
                switch(this.config.shape) {
                    case 'goose':
                        this.drawGoose();
                        break;
                    case 'sparrow':
                        this.drawSparrow();
                        break;
                    case 'mallard':
                        this.drawMallard();
                        break;
                    default:
                        this.drawDuck();
                }

                ctx.restore();
            }

            drawGoose() {
                // 身体渐变色
                const bodyGradient = ctx.createLinearGradient(-this.width/2, 0, this.width/2, 0);
                bodyGradient.addColorStop(0, '#696969');
                bodyGradient.addColorStop(0.5, '#808080');
                bodyGradient.addColorStop(1, '#696969');
                ctx.fillStyle = bodyGradient;

                // 身体
                ctx.beginPath();
                ctx.ellipse(0, 0, this.width/2, this.height/3, 0, 0, Math.PI * 2);
                ctx.fill();

                // 尾部
                ctx.beginPath();
                ctx.moveTo(-this.width/2, 0);
                ctx.lineTo(-this.width/2 - 10, -5);
                ctx.lineTo(-this.width/2 - 10, 5);
                ctx.closePath();
                ctx.fill();

                // S形脖子
                ctx.beginPath();
                ctx.moveTo(this.width/3, -2);
                ctx.bezierCurveTo(
                    this.width/2, -this.height/2,
                    this.width/2 + 5, -this.height/1.5,
                    this.width/2 + 10, -this.height/1.2
                );
                ctx.lineWidth = 4;
                ctx.stroke();

                // 头部
                ctx.fillStyle = this.config.color;
                ctx.beginPath();
                ctx.ellipse(this.width/2 + 10, -this.height/1.2, 6, 8, Math.PI/4, 0, Math.PI * 2);
                ctx.fill();

                // 喙
                ctx.fillStyle = '#000000';
                ctx.beginPath();
                ctx.moveTo(this.width/2 + 15, -this.height/1.2);
                ctx.lineTo(this.width/2 + 22, -this.height/1.2);
                ctx.lineTo(this.width/2 + 18, -this.height/1.2 + 3);
                ctx.closePath();
                ctx.fill();

                // 翅膀（分为三段）
                this.drawDetailedWing(0.7);
            }

            drawSparrow() {
                // 身体渐变
                const bodyGradient = ctx.createLinearGradient(0, -this.height/2, 0, this.height/2);
                bodyGradient.addColorStop(0, '#8B7355');
                bodyGradient.addColorStop(0.5, '#A0522D');
                bodyGradient.addColorStop(1, '#8B7355');
                ctx.fillStyle = bodyGradient;

                // 圆形身体
                ctx.beginPath();
                ctx.ellipse(0, 0, this.width/3, this.height/2.5, 0, 0, Math.PI * 2);
                ctx.fill();

                // 尾部（分叉的）
                ctx.beginPath();
                ctx.moveTo(-this.width/3, -2);
                ctx.lineTo(-this.width/2 - 5, -5);
                ctx.lineTo(-this.width/2, 0);
                ctx.lineTo(-this.width/2 - 5, 5);
                ctx.closePath();
                ctx.fill();

                // 头部
                ctx.beginPath();
                ctx.arc(this.width/4, -this.height/6, this.width/5, 0, Math.PI * 2);
                ctx.fill();

                // 小眼睛
                ctx.fillStyle = '#000000';
                ctx.beginPath();
                ctx.arc(this.width/3, -this.height/6, 1.5, 0, Math.PI * 2);
                ctx.fill();

                // 小喙
                ctx.beginPath();
                ctx.moveTo(this.width/3 + 2, -this.height/6);
                ctx.lineTo(this.width/3 + 6, -this.height/6);
                ctx.lineTo(this.width/3 + 4, -this.height/6 + 2);
                ctx.closePath();
                ctx.fill();

                // 小巧的翅膀
                this.drawDetailedWing(0.4);
            }

            drawMallard() {
                // 身体渐变
                const bodyGradient = ctx.createLinearGradient(0, -this.height/2, 0, this.height/2);
                bodyGradient.addColorStop(0, '#556B2F');
                bodyGradient.addColorStop(0.5, '#6B8E23');
                bodyGradient.addColorStop(1, '#556B2F');
                ctx.fillStyle = bodyGradient;

                // 身体
                ctx.beginPath();
                ctx.ellipse(0, 0, this.width/2, this.height/2, 0, 0, Math.PI * 2);
                ctx.fill();

                // 尾部
                ctx.beginPath();
                ctx.moveTo(-this.width/2, -2);
                ctx.lineTo(-this.width/2 - 8, -8);
                ctx.lineTo(-this.width/2 - 8, 8);
                ctx.closePath();
                ctx.fill();

                // 头部
                ctx.beginPath();
                ctx.arc(this.width/2, -5, 10, 0, Math.PI * 2);
                ctx.fill();

                // 绿头
                const headGradient = ctx.createRadialGradient(
                    this.width/2, -5, 0,
                    this.width/2, -5, 10
                );
                headGradient.addColorStop(0, '#228B22');
                headGradient.addColorStop(1, '#006400');
                ctx.fillStyle = headGradient;
                ctx.beginPath();
                ctx.arc(this.width/2, -5, 8, 0, Math.PI * 2);
                ctx.fill();

                // 眼睛
                ctx.fillStyle = '#000000';
                ctx.beginPath();
                ctx.arc(this.width/2 + 5, -7, 2, 0, Math.PI * 2);
                ctx.fill();

                // 喙
                ctx.fillStyle = '#FFA500';
                ctx.beginPath();
                ctx.moveTo(this.width/2 + 8, -5);
                ctx.lineTo(this.width/2 + 15, -5);
                ctx.lineTo(this.width/2 + 12, -2);
                ctx.closePath();
                ctx.fill();

                this.drawDetailedWing(0.6);
            }

            drawDuck() {
                // 身体渐变
                const bodyGradient = ctx.createLinearGradient(0, -this.height/2, 0, this.height/2);
                bodyGradient.addColorStop(0, '#8B4513');
                bodyGradient.addColorStop(0.5, '#DEB887');
                bodyGradient.addColorStop(1, '#8B4513');
                ctx.fillStyle = bodyGradient;

                // 身体
                ctx.beginPath();
                ctx.ellipse(0, 0, this.width/2, this.height/2, 0, 0, Math.PI * 2);
                ctx.fill();

                // 尾部
                ctx.beginPath();
                ctx.moveTo(-this.width/2, 0);
                ctx.lineTo(-this.width/2 - 10, -5);
                ctx.lineTo(-this.width/2 - 5, 0);
                ctx.lineTo(-this.width/2 - 10, 5);
                ctx.closePath();
                ctx.fill();

                // 头部
                ctx.beginPath();
                ctx.arc(this.width/2, -5, 8, 0, Math.PI * 2);
                ctx.fill();

                // 眼睛
                ctx.fillStyle = '#000000';
                ctx.beginPath();
                ctx.arc(this.width/2 + 4, -7, 2, 0, Math.PI * 2);
                ctx.fill();

                // 喙
                ctx.fillStyle = '#FFA500';
                ctx.beginPath();
                ctx.moveTo(this.width/2 + 7, -5);
                ctx.lineTo(this.width/2 + 14, -5);
                ctx.lineTo(this.width/2 + 11, -2);
                ctx.closePath();
                ctx.fill();

                this.drawDetailedWing(0.5);
            }

            drawDetailedWing(scale) {
                if (this.isShot) return;

                ctx.save();
                ctx.translate(0, 0);
                
                // 计算翅膀角度，添加自然的弧度
                const baseWingAngle = this.wingAngle;
                const wingTipAngle = baseWingAngle * 1.2; // 翅膀尖端弯曲更大

                // 主翅膀
                ctx.rotate(baseWingAngle);
                ctx.fillStyle = this.config.color;
                
                // 翅膀分为三段，创造更自然的效果
                // 第一段（靠近身体）
                ctx.beginPath();
                ctx.ellipse(-5, 0, 15 * scale, 4, 0, 0, Math.PI * 2);
                ctx.fill();

                // 第二段（中间）
                ctx.save();
                ctx.translate(-5, 0);
                ctx.rotate(wingTipAngle * 0.3);
                ctx.beginPath();
                ctx.ellipse(-10, 0, 12 * scale, 3, 0, 0, Math.PI * 2);
                ctx.fill();
                ctx.restore();

                // 第三段（翅膀尖）
                ctx.save();
                ctx.translate(-15, 0);
                ctx.rotate(wingTipAngle * 0.5);
                ctx.beginPath();
                ctx.ellipse(-8, 0, 8 * scale, 2, 0, 0, Math.PI * 2);
                ctx.fill();
                ctx.restore();

                // 添加羽毛细节
                this.drawFeatherDetails(scale);

                ctx.restore();
            }

            drawFeatherDetails(scale) {
                // 绘制羽毛纹理
                const featherColor = ctx.fillStyle;
                ctx.strokeStyle = featherColor;
                ctx.lineWidth = 0.5;

                // 主翅膀羽毛
                for (let i = 0; i < 3; i++) {
                    ctx.beginPath();
                    ctx.moveTo(-5 - i * 8, -2 * scale);
                    ctx.quadraticCurveTo(
                        -10 - i * 8, -1 * scale,
                        -15 - i * 8, -3 * scale
                    );
                    ctx.stroke();
                }

                // 次级飞羽
                for (let i = 0; i < 4; i++) {
                    ctx.beginPath();
                    ctx.moveTo(-5 - i * 6, 2 * scale);
                    ctx.quadraticCurveTo(
                        -8 - i * 6, 3 * scale,
                        -11 - i * 6, 2 * scale
                    );
                    ctx.stroke();
                }
            }

            drawSplashEffects() {
                ctx.save();
                
                // 绘制波纹
                this.ripples.forEach(ripple => {
                    ctx.strokeStyle = `rgba(255, 255, 255, ${ripple.alpha})`;
                    ctx.lineWidth = 1.5;
                    ctx.beginPath();
                    ctx.arc(ripple.x, ripple.y, ripple.radius, 0, Math.PI * 2);
                    ctx.stroke();
                    
                    // 添加次级波纹
                    ctx.strokeStyle = `rgba(255, 255, 255, ${ripple.alpha * 0.5})`;
                    ctx.lineWidth = 1;
                    ctx.beginPath();
                    ctx.arc(ripple.x, ripple.y, ripple.radius * 0.7, 0, Math.PI * 2);
                    ctx.stroke();
                });
                
                // 绘制水花粒子
                this.splashes.forEach(splash => {
                    if (splash.type === 'column' || splash.type === 'droplet') {
                        // 水柱和水滴
                        const gradient = ctx.createRadialGradient(
                            splash.x, splash.y, 0,
                            splash.x, splash.y, splash.size
                        );
                        gradient.addColorStop(0, `rgba(255, 255, 255, ${splash.alpha})`);
                        gradient.addColorStop(1, `rgba(200, 240, 255, ${splash.alpha * 0.7})`);
                        
                        ctx.fillStyle = gradient;
                        ctx.beginPath();
                        ctx.arc(splash.x, splash.y, splash.size, 0, Math.PI * 2);
                        ctx.fill();
                        
                        // 水滴拖尾效果
                        if (splash.type === 'droplet' && splash.speedY < 0) {
                            ctx.strokeStyle = `rgba(255, 255, 255, ${splash.alpha * 0.3})`;
                            ctx.lineWidth = 1;
                            ctx.beginPath();
                            ctx.moveTo(splash.x, splash.y);
                            ctx.lineTo(splash.x - splash.speedX * 2, splash.y - splash.speedY * 2);
                            ctx.stroke();
                        }
                    } else if (splash.type === 'splash' && splash.progress <= 1) {
                        // 水面飞溅
                        ctx.fillStyle = `rgba(220, 240, 255, ${splash.alpha})`;
                        ctx.beginPath();
                        ctx.arc(splash.currentX, splash.currentY, splash.size, 0, Math.PI * 2);
                        ctx.fill();
                    }
                });
                
                ctx.restore();
            }

            isOutOfScreen() {
                // 修改出界判定，被击中的鸟不会消失
                if (this.isShot) {
                    return false;
                }
                return this.y > canvas.height || this.x < -50 || this.x > canvas.width + 50;
            }
        }

        // 添加子弹类
        class Bullet {
            constructor(startX, startY) {
                this.x = startX;
                this.y = startY;
                this.speed = 15;
                this.size = 3;
                this.active = true;
            }

            update() {
                this.y -= this.speed;
                // 如果子弹飞出屏幕，标记为非活跃
                if (this.y < 0) {
                    this.active = false;
                }
            }

            draw() {
                ctx.fillStyle = '#FFD700';
                ctx.beginPath();
                ctx.arc(this.x, this.y, this.size, 0, Math.PI * 2);
                ctx.fill();
                
                // 添加子弹轨迹
                ctx.strokeStyle = 'rgba(255, 215, 0, 0.5)';
                ctx.lineWidth = 2;
                ctx.beginPath();
                ctx.moveTo(this.x, this.y + 10);
                ctx.lineTo(this.x, this.y + 20);
                ctx.stroke();
            }

            checkCollision(bird) {
                if (!bird.isShot) {
                    const dx = Math.abs(this.x - bird.x);
                    const dy = Math.abs(this.y - bird.y);
                    return dx < 30 && dy < 30;
                }
                return false;
            }
        }

        // Draw background
        function drawBackground() {
            // 绘制天空渐变
            const skyGradient = ctx.createLinearGradient(0, 0, 0, canvas.height);
            skyGradient.addColorStop(0, '#87CEEB');
            skyGradient.addColorStop(1, '#B0E0E6');
            ctx.fillStyle = skyGradient;
            ctx.fillRect(0, 0, canvas.width, canvas.height);

            // 绘制湖面
            const waterGradient = ctx.createLinearGradient(0, canvas.height - 200, 0, canvas.height);
            waterGradient.addColorStop(0, '#4682B4');
            waterGradient.addColorStop(1, '#1E90FF');
            ctx.fillStyle = waterGradient;
            ctx.fillRect(0, canvas.height - 200, canvas.width, 200);

            // 添加动态水波效果
            drawWaterWaves();
            
            // 绘制水下场景
            drawUnderwaterScene();

            // 绘制草丛（更自然的形状）
            ctx.fillStyle = '#2F4F4F';
            for (let i = 0; i < canvas.width; i += 30) {
                const height = 80 + Math.sin(i * 0.1) * 20;
                drawGrass(i, canvas.height - height, 30, height);
            }
            
            // 绘制船
            drawBoat();
        }
        
        // 绘制水下场景
        function drawUnderwaterScene() {
            // 绘制水底的泥沙
            const sandGradient = ctx.createLinearGradient(0, canvas.height - 50, 0, canvas.height);
            sandGradient.addColorStop(0, '#8B4513');
            sandGradient.addColorStop(1, '#A0522D');
            ctx.fillStyle = sandGradient;
            
            // 波浪形的沙底
            ctx.beginPath();
            ctx.moveTo(0, canvas.height - 30);
            
            for (let x = 0; x < canvas.width; x += 50) {
                const height = Math.sin(x * 0.03) * 10 + Math.sin(x * 0.02 + Date.now() * 0.0003) * 5;
                ctx.lineTo(x, canvas.height - 20 + height);
            }
            
            ctx.lineTo(canvas.width, canvas.height);
            ctx.lineTo(0, canvas.height);
            ctx.closePath();
            ctx.fill();
            
            // 绘制水草
            drawWaterWeeds();
            
            // 绘制鱼群
            drawFishes();
            
            // 添加一些水下微粒
            drawWaterParticles();
        }
        
        // 初始化水草
        function initWaterWeeds() {
            waterWeeds = [];
            // 创建不同类型的水草
            for (let i = 0; i < 18; i++) {
                const weedType = Math.random() < 0.5 ? 'tall' : (Math.random() < 0.5 ? 'bushy' : 'kelp');
                const x = Math.random() * canvas.width;
                const height = weedType === 'tall' ? 60 + Math.random() * 40 : 
                              (weedType === 'bushy' ? 30 + Math.random() * 20 : 50 + Math.random() * 30);
                
                waterWeeds.push({
                    x,
                    y: canvas.height - 20,
                    height,
                    width: weedType === 'bushy' ? 30 : 15,
                    segments: weedType === 'kelp' ? 5 + Math.floor(Math.random() * 3) : 
                              (weedType === 'tall' ? 3 + Math.floor(Math.random() * 2) : 0),
                    type: weedType,
                    swayOffset: Math.random() * Math.PI * 2,
                    swaySpeed: 0.5 + Math.random() * 0.5,
                    color: weedType === 'tall' ? '#006400' : 
                          (weedType === 'bushy' ? '#228B22' : '#008080')
                });
            }
        }
        
        // 绘制水草
        function drawWaterWeeds() {
            // 确保水草已初始化
            if (waterWeeds.length === 0) {
                initWaterWeeds();
            }
            
            // 绘制每株水草
            waterWeeds.forEach(weed => {
                ctx.save();
                
                switch (weed.type) {
                    case 'tall':
                        drawTallWeed(weed);
                        break;
                    case 'bushy':
                        drawBushyWeed(weed);
                        break;
                    case 'kelp':
                        drawKelpWeed(weed);
                        break;
                }
                
                ctx.restore();
            });
        }
        
        // 绘制高草型水草
        function drawTallWeed(weed) {
            const time = Date.now() * 0.001;
            const sway = Math.sin(time * weed.swaySpeed + weed.swayOffset) * 10;
            
            // 创建水草的渐变色
            const gradient = ctx.createLinearGradient(0, weed.y - weed.height, 0, weed.y);
            gradient.addColorStop(0, '#32CD32');
            gradient.addColorStop(1, weed.color);
            ctx.fillStyle = gradient;
            
            // 绘制主茎
            ctx.beginPath();
            
            // 从底部开始
            ctx.moveTo(weed.x, weed.y);
            
            // 计算控制点，添加摇摆效果
            const segmentHeight = weed.height / weed.segments;
            let prevX = weed.x;
            let prevY = weed.y;
            
            for (let i = 1; i <= weed.segments; i++) {
                const segmentSway = sway * (i / weed.segments) * 1.5;
                const curveX = prevX + segmentSway;
                const curveY = prevY - segmentHeight;
                
                // 使用二次贝塞尔曲线创建自然弯曲
                const controlX = prevX + segmentSway * 0.5;
                const controlY = prevY - segmentHeight * 0.5;
                
                ctx.quadraticCurveTo(controlX, controlY, curveX, curveY);
                
                prevX = curveX;
                prevY = curveY;
            }
            
            // 绘制右侧边缘返回底部
            ctx.lineTo(prevX + weed.width/4, prevY);
            
            for (let i = weed.segments; i >= 1; i--) {
                const segmentSway = sway * (i / weed.segments) * 1.5;
                const curveX = weed.x + segmentSway + weed.width/2;
                const curveY = weed.y - (weed.height / weed.segments) * (i - 1);
                
                // 使用二次贝塞尔曲线返回
                const controlX = weed.x + segmentSway * 0.5 + weed.width/2;
                const controlY = weed.y - (weed.height / weed.segments) * (i - 0.5);
                
                ctx.quadraticCurveTo(controlX, controlY, curveX, curveY);
            }
            
            ctx.closePath();
            ctx.fill();
            
            // 添加一些细节线条
            ctx.strokeStyle = 'rgba(0, 50, 0, 0.3)';
            ctx.lineWidth = 0.5;
            
            // 中心线
            ctx.beginPath();
            ctx.moveTo(weed.x, weed.y);
            prevX = weed.x;
            prevY = weed.y;
            
            for (let i = 1; i <= weed.segments; i++) {
                const segmentSway = sway * (i / weed.segments) * 1.5;
                const curveX = prevX + segmentSway;
                const curveY = prevY - segmentHeight;
                
                const controlX = prevX + segmentSway * 0.5;
                const controlY = prevY - segmentHeight * 0.5;
                
                ctx.quadraticCurveTo(controlX, controlY, curveX, curveY);
                
                prevX = curveX;
                prevY = curveY;
            }
            
            ctx.stroke();
        }
        
        // 绘制丛生型水草
        function drawBushyWeed(weed) {
            const time = Date.now() * 0.001;
            
            // 创建水草的渐变色
            const gradient = ctx.createLinearGradient(0, weed.y - weed.height, 0, weed.y);
            gradient.addColorStop(0, '#32CD32');
            gradient.addColorStop(1, weed.color);
            ctx.fillStyle = gradient;
            
            // 绘制多个叶片
            const leafCount = 6 + Math.floor(Math.random() * 4);
            
            for (let i = 0; i < leafCount; i++) {
                const angle = (i / leafCount) * Math.PI;
                const sway = Math.sin(time * weed.swaySpeed + weed.swayOffset + i) * 5;
                
                ctx.save();
                ctx.translate(weed.x + (i - leafCount/2) * (weed.width/leafCount), weed.y);
                ctx.rotate(-Math.PI/2 + angle * 0.2 + sway * 0.02);
                
                // 叶片形状
                ctx.beginPath();
                ctx.moveTo(0, 0);
                ctx.bezierCurveTo(
                    weed.height * 0.3, -weed.width * 0.2,
                    weed.height * 0.7, -weed.width * 0.1,
                    weed.height, 0
                );
                ctx.bezierCurveTo(
                    weed.height * 0.7, weed.width * 0.1,
                    weed.height * 0.3, weed.width * 0.2,
                    0, 0
                );
                ctx.fill();
                
                // 叶脉
                ctx.strokeStyle = 'rgba(0, 40, 0, 0.2)';
                ctx.lineWidth = 0.5;
                ctx.beginPath();
                ctx.moveTo(0, 0);
                ctx.lineTo(weed.height, 0);
                ctx.stroke();
                
                ctx.restore();
            }
        }
        
        // 绘制海带型水草
        function drawKelpWeed(weed) {
            const time = Date.now() * 0.001;
            const sway = Math.sin(time * weed.swaySpeed + weed.swayOffset) * 15;
            
            // 创建水草的渐变色
            const gradient = ctx.createLinearGradient(0, weed.y - weed.height, 0, weed.y);
            gradient.addColorStop(0, '#20B2AA');
            gradient.addColorStop(1, weed.color);
            ctx.fillStyle = gradient;
            
            // 绘制主茎
            ctx.beginPath();
            ctx.moveTo(weed.x, weed.y);
            
            // 计算控制点，添加摇摆效果
            const segmentHeight = weed.height / weed.segments;
            let prevX = weed.x;
            let prevY = weed.y;
            
            for (let i = 1; i <= weed.segments; i++) {
                const segmentSway = sway * (i / weed.segments) * 1.2;
                const curveX = prevX + segmentSway;
                const curveY = prevY - segmentHeight;
                
                // 使用二次贝塞尔曲线创建自然弯曲
                const controlX = prevX + segmentSway * 0.5;
                const controlY = prevY - segmentHeight * 0.5;
                
                ctx.quadraticCurveTo(controlX, controlY, curveX, curveY);
                
                // 绘制气泡囊
                if (i < weed.segments) {
                    ctx.save();
                    ctx.translate(curveX, curveY);
                    
                    // 左侧叶片
                    ctx.beginPath();
                    ctx.ellipse(-10, 0, 8, 15, 0, 0, Math.PI * 2);
                    ctx.fill();
                    
                    // 右侧叶片
                    ctx.beginPath();
                    ctx.ellipse(10, 0, 8, 15, 0, 0, Math.PI * 2);
                    ctx.fill();
                    
                    ctx.restore();
                }
                
                prevX = curveX;
                prevY = curveY;
            }
            
            // 绘制顶部叶片
            ctx.save();
            ctx.translate(prevX, prevY);
            
            ctx.beginPath();
            ctx.ellipse(0, -10, 12, 20, 0, 0, Math.PI * 2);
            ctx.fill();
            
            ctx.restore();
            
            // 绘制主茎轮廓
            ctx.lineWidth = 2;
            ctx.strokeStyle = 'rgba(0, 80, 80, 0.3)';
            ctx.stroke();
        }
        
        // 初始化鱼群
        function initFishes() {
            fishes = [];
            
            // 创建不同的鱼
            const fishTypes = ['small', 'medium', 'large'];
            const fishColors = [
                {body: '#FFD700', tail: '#FFA500'}, // 金色
                {body: '#87CEEB', tail: '#1E90FF'}, // 蓝色
                {body: '#FA8072', tail: '#CD5C5C'}, // 红色
                {body: '#90EE90', tail: '#32CD32'}  // 绿色
            ];
            
            // 减少鱼的数量，只创建2条鱼
            for (let i = 0; i < 2; i++) {
                const type = fishTypes[Math.floor(Math.random() * fishTypes.length)];
                const color = fishColors[Math.floor(Math.random() * fishColors.length)];
                const speed = (type === 'small') ? 0.5 + Math.random() * 0.5 : 
                             (type === 'medium') ? 0.3 + Math.random() * 0.3 : 
                             0.2 + Math.random() * 0.2;
                
                // 放置在屏幕外，让鱼偶尔游入
                const side = Math.random() < 0.5 ? -1 : 1;
                
                fishes.push({
                    x: side < 0 ? -50 : canvas.width + 50, // 放在屏幕外
                    y: canvas.height - 150 + Math.random() * 120,
                    speed: speed * side,
                    type,
                    color,
                    tailAngle: 0,
                    tailSpeed: 0.1 + Math.random() * 0.1,
                    bodyWidth: (type === 'small') ? 15 : 
                              (type === 'medium') ? 25 : 40,
                    bodyHeight: (type === 'small') ? 8 : 
                                (type === 'medium') ? 12 : 20,
                    offset: Math.random() * Math.PI * 2,
                    verticalOffset: Math.random() * 10,
                    active: false, // 初始设为不活跃
                    nextActivationTime: Date.now() + Math.random() * 15000 + 5000 // 随机5-20秒后激活
                });
            }
        }
        
        // 绘制鱼群
        function drawFishes() {
            // 确保鱼群已初始化
            if (fishes.length === 0) {
                initFishes();
            }
            
            const time = Date.now() * 0.001;
            const now = Date.now();
            
            // 更新和绘制每条鱼
            fishes.forEach(fish => {
                // 检查鱼是否应该激活
                if (!fish.active && now >= fish.nextActivationTime) {
                    fish.active = true;
                    // 重新放置在屏幕边缘
                    const side = Math.random() < 0.5 ? -1 : 1;
                    fish.x = side < 0 ? -fish.bodyWidth * 2 : canvas.width + fish.bodyWidth * 2;
                    fish.y = canvas.height - 150 + Math.random() * 120;
                    fish.speed = (fish.type === 'small' ? 0.5 + Math.random() * 0.5 : 
                                fish.type === 'medium' ? 0.3 + Math.random() * 0.3 : 
                                0.2 + Math.random() * 0.2) * side;
                }
                
                // 只更新活跃的鱼
                if (fish.active) {
                    // 更新鱼的位置
                    fish.x += fish.speed;
                    
                    // 垂直方向的轻微浮动
                    fish.y = fish.y + Math.sin(time + fish.offset) * 0.3;
                    
                    // 尾巴摆动动画
                    fish.tailAngle = Math.sin(time * 5 * fish.tailSpeed + fish.offset) * 0.3;
                    
                    // 如果鱼游出画面，设置为非活跃，并安排下次出现时间
                    if ((fish.speed < 0 && fish.x < -fish.bodyWidth * 2) || 
                        (fish.speed > 0 && fish.x > canvas.width + fish.bodyWidth * 2)) {
                        fish.active = false;
                        fish.nextActivationTime = now + Math.random() * 20000 + 10000; // 随机10-30秒后再次出现
                    }
                    
                    // 绘制鱼
                    ctx.save();
                    ctx.translate(fish.x, fish.y);
                    
                    // 根据游动方向调整鱼的朝向
                    if (fish.speed < 0) {
                        ctx.scale(-1, 1);
                    }
                    
                    // 绘制鱼身
                    const bodyGradient = ctx.createLinearGradient(
                        0, -fish.bodyHeight/2, 
                        0, fish.bodyHeight/2
                    );
                    bodyGradient.addColorStop(0, fish.color.body);
                    bodyGradient.addColorStop(0.5, lightenColor(fish.color.body, 20));
                    bodyGradient.addColorStop(1, fish.color.body);
                    
                    ctx.fillStyle = bodyGradient;
                    ctx.beginPath();
                    ctx.ellipse(0, 0, fish.bodyWidth, fish.bodyHeight, 0, 0, Math.PI * 2);
                    ctx.fill();
                    
                    // 绘制尾巴
                    ctx.save();
                    ctx.translate(-fish.bodyWidth, 0);
                    ctx.rotate(fish.tailAngle);
                    
                    ctx.fillStyle = fish.color.tail;
                    ctx.beginPath();
                    ctx.moveTo(0, 0);
                    ctx.lineTo(-fish.bodyWidth * 0.7, -fish.bodyHeight);
                    ctx.lineTo(-fish.bodyWidth * 0.7, fish.bodyHeight);
                    ctx.closePath();
                    ctx.fill();
                    
                    ctx.restore();
                    
                    // 绘制鱼鳍
                    ctx.fillStyle = fish.color.tail;
                    
                    // 顶部鳍
                    ctx.beginPath();
                    ctx.moveTo(0, -fish.bodyHeight);
                    ctx.quadraticCurveTo(
                        fish.bodyWidth * 0.3, -fish.bodyHeight * 1.8,
                        -fish.bodyWidth * 0.2, -fish.bodyHeight
                    );
                    ctx.closePath();
                    ctx.fill();
                    
                    // 底部鳍
                    ctx.beginPath();
                    ctx.moveTo(0, fish.bodyHeight);
                    ctx.quadraticCurveTo(
                        -fish.bodyWidth * 0.3, fish.bodyHeight * 1.5,
                        -fish.bodyWidth * 0.5, fish.bodyHeight
                    );
                    ctx.closePath();
                    ctx.fill();
                    
                    // 绘制眼睛
                    ctx.fillStyle = 'white';
                    ctx.beginPath();
                    ctx.arc(fish.bodyWidth * 0.6, -fish.bodyHeight * 0.2, fish.bodyHeight * 0.3, 0, Math.PI * 2);
                    ctx.fill();
                    
                    ctx.fillStyle = 'black';
                    ctx.beginPath();
                    ctx.arc(fish.bodyWidth * 0.6, -fish.bodyHeight * 0.2, fish.bodyHeight * 0.15, 0, Math.PI * 2);
                    ctx.fill();
                    
                    ctx.restore();
                }
            });
        }
        
        // 辅助函数：增亮颜色
        function lightenColor(color, percent) {
            const num = parseInt(color.replace('#', ''), 16);
            const amt = Math.round(2.55 * percent);
            const R = (num >> 16) + amt;
            const G = (num >> 8 & 0x00FF) + amt;
            const B = (num & 0x0000FF) + amt;
            
            return '#' + (
                0x1000000 + 
                (R < 255 ? (R < 1 ? 0 : R) : 255) * 0x10000 + 
                (G < 255 ? (G < 1 ? 0 : G) : 255) * 0x100 + 
                (B < 255 ? (B < 1 ? 0 : B) : 255)
            ).toString(16).slice(1);
        }
        
        // 绘制水下微粒
        function drawWaterParticles() {
            const time = Date.now() * 0.001;
            
            // 绘制随机漂浮的微粒
            ctx.fillStyle = 'rgba(255, 255, 255, 0.3)';
            
            for (let i = 0; i < 50; i++) {
                const x = ((time * 10 + i * 100) % canvas.width);
                const y = canvas.height - 100 - Math.abs(Math.sin(time * 0.5 + i)) * 80;
                const size = 0.5 + Math.sin(time + i) * 0.5;
                
                ctx.beginPath();
                ctx.arc(x, y, size, 0, Math.PI * 2);
                ctx.fill();
            }
        }
        
        // 绘制草丛
        function drawGrass(x, y, width, height) {
            ctx.beginPath();
            ctx.moveTo(x, y + height);
            
            // 绘制草的形状
            for (let i = 0; i < 3; i++) {
                const cp1x = x + width * 0.2 + Math.random() * 5;
                const cp1y = y + height * 0.3;
                const cp2x = x + width * 0.8 + Math.random() * 5;
                const cp2y = y + height * 0.3;
                const endX = x + width;
                const endY = y + height;
                
                ctx.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, endX, endY);
            }
            
            ctx.fillStyle = '#228B22';
            ctx.fill();
        }
        
        // 绘制船
        function drawBoat() {
            // 绘制船身
            const boatX = canvas.width * 0.5;
            const boatY = canvas.height - 70;
            
            ctx.save();
            
            // 添加船的轻微摇晃
            const time = Date.now() * 0.001;
            const rockAngle = Math.sin(time * 0.5) * 0.02;
            
            ctx.translate(boatX, canvas.height - 100);
            ctx.rotate(rockAngle);
            
            // 船身渐变
            const hullGradient = ctx.createLinearGradient(-80, 0, 80, 0);
            hullGradient.addColorStop(0, '#8B4513');
            hullGradient.addColorStop(0.4, '#A0522D');
            hullGradient.addColorStop(0.6, '#A0522D');
            hullGradient.addColorStop(1, '#8B4513');
            ctx.fillStyle = hullGradient;
            
            // 船身
            ctx.beginPath();
            ctx.moveTo(-80, 0);
            ctx.quadraticCurveTo(-60, -20, 0, -25);
            ctx.quadraticCurveTo(60, -20, 80, 0);
            ctx.lineTo(70, 50);
            ctx.lineTo(-70, 50);
            ctx.closePath();
            ctx.fill();
            
            // 船边缘
            ctx.strokeStyle = '#6B4226';
            ctx.lineWidth = 2;
            ctx.stroke();
            
            // 船内部
            ctx.fillStyle = '#D2B48C';
            ctx.beginPath();
            ctx.moveTo(-70, 0);
            ctx.quadraticCurveTo(-50, -15, 0, -20);
            ctx.quadraticCurveTo(50, -15, 70, 0);
            ctx.closePath();
            ctx.fill();
            
            // 船桨
            ctx.strokeStyle = '#8B4513';
            ctx.lineWidth = 3;
            
            // 左桨
            ctx.save();
            const paddleOffset = Math.sin(time * 2) * 5;
            ctx.translate(-50, 10);
            ctx.rotate(-Math.PI/4 + Math.sin(time * 2) * 0.1);
            ctx.beginPath();
            ctx.moveTo(0, 0);
            ctx.lineTo(-40, 30);
            ctx.stroke();
            
            // 桨叶
            ctx.fillStyle = '#A0522D';
            ctx.beginPath();
            ctx.ellipse(-45, 35, 10, 5, -Math.PI/4, 0, Math.PI * 2);
            ctx.fill();
            ctx.restore();
            
            // 右桨
            ctx.save();
            ctx.translate(50, 10);
            ctx.rotate(Math.PI/4 - Math.sin(time * 2 + 1) * 0.1);
            ctx.beginPath();
            ctx.moveTo(0, 0);
            ctx.lineTo(40, 30);
            ctx.stroke();
            
            // 桨叶
            ctx.fillStyle = '#A0522D';
            ctx.beginPath();
            ctx.ellipse(45, 35, 10, 5, Math.PI/4, 0, Math.PI * 2);
            ctx.fill();
            ctx.restore();
            
            // 船上的猎人剪影
            ctx.fillStyle = '#000';
            ctx.beginPath();
            ctx.ellipse(0, -5, 15, 25, 0, 0, Math.PI * 2);
            ctx.fill();
            
            // 猎人的帽子
            ctx.beginPath();
            ctx.moveTo(-10, -25);
            ctx.lineTo(10, -25);
            ctx.lineTo(7, -35);
            ctx.lineTo(-7, -35);
            ctx.closePath();
            ctx.fill();
            
            ctx.restore();
        }

        // Draw gun
        function drawGun() {
            const gunX = gunPosition.x;
            const gunY = gunPosition.y;
            
            ctx.save();
            ctx.translate(gunX, gunY);
            
            // 绘制手枪
            // 枪管
            ctx.fillStyle = '#333';
            ctx.beginPath();
            ctx.rect(-5, -30, 10, 20);
            ctx.fill();
            
            // 枪身渐变
            const gunGradient = ctx.createLinearGradient(-15, 0, 15, 0);
            gunGradient.addColorStop(0, '#555');
            gunGradient.addColorStop(0.5, '#777');
            gunGradient.addColorStop(1, '#555');
            ctx.fillStyle = gunGradient;
            
            // 枪身
            ctx.beginPath();
            ctx.rect(-15, -10, 30, 20);
            ctx.fill();
            
            // 握把
            ctx.beginPath();
            ctx.moveTo(-10, 10);
            ctx.lineTo(-10, 30);
            ctx.lineTo(10, 30);
            ctx.lineTo(10, 10);
            ctx.closePath();
            ctx.fill();
            
            // 扳机护圈
            ctx.fillStyle = '#444';
            ctx.beginPath();
            ctx.arc(0, 0, 8, 0, Math.PI, true);
            ctx.fill();
            
            // 扳机
            ctx.fillStyle = '#333';
            ctx.beginPath();
            ctx.rect(-2, 0, 4, 8);
            ctx.fill();
            
            // 枪膛和准星
            ctx.fillStyle = '#222';
            ctx.beginPath();
            ctx.rect(-7, -32, 14, 2);
            ctx.fill();
            
            // 简化瞄准线为一条竖线
            ctx.strokeStyle = 'rgba(255, 255, 255, 0.5)';
            ctx.lineWidth = 1;
            ctx.beginPath();
            ctx.moveTo(0, -30);
            ctx.lineTo(0, -100);
            ctx.stroke();
            
            // 高光反射
            ctx.strokeStyle = 'rgba(255, 255, 255, 0.3)';
            ctx.lineWidth = 1;
            ctx.beginPath();
            ctx.moveTo(-15, -5);
            ctx.lineTo(15, -5);
            ctx.stroke();
            
            ctx.restore();
        }

        // Draw score and bullets
        function drawScore() {
            ctx.fillStyle = '#000';
            ctx.font = '24px Arial';
            ctx.fillText(`Score: ${score}`, 20, 30);
            
            // Draw bullets
            ctx.fillText(`Bullets: ${bullets}/${maxBullets}`, 20, 60);
            
            // Reloading indicator
            if (reloading) {
                ctx.fillText('Reloading...', 20, 90);
            } else if (bullets === 0) {
                ctx.fillStyle = '#FF0000';
                ctx.fillText('Press R to reload', 20, 90);
            }
        }

        // Handle mouse movement
        canvas.addEventListener('mousemove', (e) => {
            const rect = canvas.getBoundingClientRect();
            gunPosition.x = e.clientX - rect.left;
        });

        // Handle shooting
        canvas.addEventListener('click', () => {
            if (bullets <= 0 || reloading) return;
            
            bullets--;
            SoundSystem.play('SHOOT');
            
            // 创建新子弹
            const bullet = new Bullet(gunPosition.x, gunPosition.y - 30);
            activeBullets.push(bullet);
        });

        // Handle reloading
        document.addEventListener('keydown', (e) => {
            if (e.key.toLowerCase() === 'r' && !reloading && bullets < maxBullets) {
                reloading = true;
                SoundSystem.play('RELOAD');
                
                // Reload takes 2 seconds
                setTimeout(() => {
                    bullets = maxBullets;
                    reloading = false;
                }, 2000);
            }
        });

        // 添加游戏手柄支持
        window.addEventListener("gamepadconnected", (e) => {
            console.log("游戏手柄已连接：", e.gamepad.id);
            gamepadConnected = true;
            gamepad = e.gamepad;
            
            // 显示手柄连接提示
            const gamepadInfo = document.createElement("div");
            gamepadInfo.id = "gamepad-info";
            gamepadInfo.style.position = "absolute";
            gamepadInfo.style.top = "10px";
            gamepadInfo.style.right = "10px";
            gamepadInfo.style.background = "rgba(0,0,0,0.5)";
            gamepadInfo.style.color = "white";
            gamepadInfo.style.padding = "10px";
            gamepadInfo.style.borderRadius = "5px";
            gamepadInfo.textContent = "游戏手柄已连接";
            document.body.appendChild(gamepadInfo);
            
            // 显示控制按钮
            document.getElementById('show-controls').style.display = 'block';
            
            // 设置控制面板事件处理
            document.getElementById('show-controls').addEventListener('click', function() {
                document.getElementById('controls-panel').style.display = 'block';
            });
            
            document.getElementById('close-btn').addEventListener('click', function() {
                document.getElementById('controls-panel').style.display = 'none';
            });
            
            document.getElementById('sensitivity').addEventListener('input', function(e) {
                gamepadSensitivity = parseInt(e.target.value);
                document.getElementById('sensitivity-value').textContent = gamepadSensitivity;
            });
            
            // 3秒后隐藏提示
            setTimeout(() => {
                gamepadInfo.style.opacity = "0";
                gamepadInfo.style.transition = "opacity 1s";
                setTimeout(() => gamepadInfo.remove(), 1000);
            }, 3000);
        });

        window.addEventListener("gamepaddisconnected", (e) => {
            console.log("游戏手柄已断开连接：", e.gamepad.id);
            gamepadConnected = false;
            gamepad = null;
        });

        // 处理游戏手柄输入
        function handleGamepad() {
            if (!gamepadConnected) return;
            
            // 获取最新的手柄状态
            const gamepads = navigator.getGamepads();
            gamepad = gamepads[0]; // 使用第一个连接的手柄
            
            if (!gamepad) return;
            
            // 使用左摇杆或方向键控制准星
            const leftStickX = gamepad.axes[0]; // 左摇杆X轴
            const dpadRight = gamepad.buttons[15]?.pressed;
            const dpadLeft = gamepad.buttons[14]?.pressed;
            
            // 移动准星 (使用摇杆或方向键)
            if (Math.abs(leftStickX) > 0.1) { // 添加死区
                gunPosition.x += leftStickX * gamepadSensitivity;
            } else if (dpadRight) {
                gunPosition.x += gamepadSensitivity;
            } else if (dpadLeft) {
                gunPosition.x -= gamepadSensitivity;
            }
            
            // 限制准星在画布范围内
            gunPosition.x = Math.max(0, Math.min(canvas.width, gunPosition.x));
            
            // 射击 (A按钮或右扳机)
            const aButton = gamepad.buttons[0]?.pressed;
            const rightTrigger = gamepad.buttons[7]?.pressed || gamepad.buttons[7]?.value > 0.5;
            
            const now = Date.now();
            if ((aButton || rightTrigger) && now - lastShootTime > shootCooldown) {
                if (bullets > 0 && !reloading) {
                    bullets--;
                    SoundSystem.play('SHOOT');
                    
                    // 创建新子弹
                    const bullet = new Bullet(gunPosition.x, gunPosition.y - 30);
                    activeBullets.push(bullet);
                    
                    lastShootTime = now;
                }
            }
            
            // 装弹 (B按钮或Y按钮)
            const bButton = gamepad.buttons[1]?.pressed;
            const yButton = gamepad.buttons[3]?.pressed;
            
            if ((bButton || yButton) && now - lastReloadTime > reloadCooldown) {
                if (!reloading && bullets < maxBullets) {
                    reloading = true;
                    SoundSystem.play('RELOAD');
                    
                    // 装弹需要2秒
                    setTimeout(() => {
                        bullets = maxBullets;
                        reloading = false;
                    }, 2000);
                    
                    lastReloadTime = now;
                }
            }
        }

        // Game loop
        function gameLoop() {
            ctx.clearRect(0, 0, canvas.width, canvas.height);
            drawBackground();
            
            // 处理游戏手柄输入
            handleGamepad();
            
            drawGun();
            drawScore();

            // 更新和绘制子弹
            activeBullets = activeBullets.filter(bullet => {
                bullet.update();
                bullet.draw();

                // 检查子弹是否击中鸟
                birds.forEach(bird => {
                    if (bullet.active && bullet.checkCollision(bird)) {
                        bird.isShot = true;
                        bullet.active = false;
                        score += BIRD_TYPES[bird.type].points;
                        SoundSystem.play('DUCK');
                    }
                });

                return bullet.active;
            });

            // 生成新的鸟
            const now = Date.now();
            if (now - lastBirdTime > 2000) {
                const birdTypes = Object.keys(BIRD_TYPES);
                const randomType = birdTypes[Math.floor(Math.random() * birdTypes.length)];
                birds.push(new Bird(randomType));
                lastBirdTime = now;
            }

            // 更新和绘制鸟
            birds = birds.filter(bird => !bird.isOutOfScreen());
            birds.forEach(bird => {
                bird.update();
                bird.draw();
            });

            requestAnimationFrame(gameLoop);
        }

        // Start game
        gameLoop();

        // 添加绘制动态水波的函数
        function drawWaterWaves() {
            const waterLevel = canvas.height - 200;
            const waveHeight = 2;
            const waveCount = 6;
            const waterColors = ['rgba(30, 144, 255, 0.4)', 'rgba(70, 130, 180, 0.3)', 'rgba(0, 191, 255, 0.2)'];
            
            // 绘制多层水波浪
            for (let layer = 0; layer < 3; layer++) {
                const time = Date.now() * (0.0004 - layer * 0.0001);
                const amplitude = waveHeight * (3 - layer);
                
                ctx.beginPath();
                ctx.moveTo(0, waterLevel);
                
                for (let x = 0; x < canvas.width; x += 10) {
                    // 使用多个正弦波叠加创造更自然的波形
                    const wave1 = Math.sin(x * 0.02 + time) * amplitude;
                    const wave2 = Math.sin(x * 0.04 + time * 0.8) * amplitude * 0.5;
                    const wave3 = Math.sin(x * 0.01 + time * 1.2) * amplitude * 0.3;
                    
                    const y = waterLevel + wave1 + wave2 + wave3;
                    ctx.lineTo(x, y);
                }
                
                // 完成水波路径
                ctx.lineTo(canvas.width, waterLevel + 200);
                ctx.lineTo(0, waterLevel + 200);
                ctx.closePath();
                
                ctx.fillStyle = waterColors[layer];
                ctx.fill();
            }
            
            // 添加水面高光效果
            ctx.save();
            ctx.globalAlpha = 0.05;
            ctx.globalCompositeOperation = 'lighter';
            
            for (let i = 0; i < 3; i++) {
                const time = Date.now() * 0.001 + i * 1.5;
                const y = waterLevel + Math.sin(time) * 20;
                
                const gradient = ctx.createLinearGradient(0, y - 5, 0, y + 5);
                gradient.addColorStop(0, 'rgba(255, 255, 255, 0)');
                gradient.addColorStop(0.5, 'rgba(255, 255, 255, 0.3)');
                gradient.addColorStop(1, 'rgba(255, 255, 255, 0)');
                
                ctx.fillStyle = gradient;
                ctx.fillRect(0, y - 5, canvas.width, 10);
            }
            
            ctx.restore();
        }

        // 添加移动设备支持
        let isMobile = /iPhone|iPad|iPod|Android/i.test(navigator.userAgent);
        
        if (isMobile) {
            // 设置画布大小以适应移动设备
            function resizeCanvas() {
                const aspectRatio = 800/600;
                if (window.innerWidth / window.innerHeight > aspectRatio) {
                    canvas.style.height = '100vh';
                    canvas.style.width = '100vh * ' + aspectRatio;
                } else {
                    canvas.style.width = '100vw';
                    canvas.style.height = '100vw / ' + aspectRatio;
                }
            }
            
            window.addEventListener('resize', resizeCanvas);
            resizeCanvas();

            // 触摸事件处理
            canvas.addEventListener('touchstart', (e) => {
                e.preventDefault();
                if (bullets <= 0 || reloading) return;
                
                const rect = canvas.getBoundingClientRect();
                const touch = e.touches[0];
                const x = (touch.clientX - rect.left) * (canvas.width / rect.width);
                const y = (touch.clientY - rect.top) * (canvas.height / rect.height);
                
                gunPosition.x = x;
                bullets--;
                SoundSystem.play('SHOOT');
                
                const bullet = new Bullet(x, gunPosition.y - 30);
                activeBullets.push(bullet);
            });

            canvas.addEventListener('touchmove', (e) => {
                e.preventDefault();
                const rect = canvas.getBoundingClientRect();
                const touch = e.touches[0];
                gunPosition.x = (touch.clientX - rect.left) * (canvas.width / rect.width);
            });

            // 移动端装弹按钮
            document.getElementById('reloadBtn').addEventListener('touchstart', (e) => {
                e.preventDefault();
                if (!reloading && bullets < maxBullets) {
                    reloading = true;
                    SoundSystem.play('RELOAD');
                    
                    setTimeout(() => {
                        bullets = maxBullets;
                        reloading = false;
                    }, 2000);
                }
            });

            // 添加屏幕方向检测
            window.addEventListener('orientationchange', () => {
                setTimeout(resizeCanvas, 100);
            });
        }

        // 修改音效系统初始化
        if (isMobile) {
            // 在移动设备上，需要用户交互才能初始化音频上下文
            document.addEventListener('touchstart', () => {
                if (!SoundSystem.audioContext) {
                    SoundSystem.init();
                }
            }, { once: true });
        }
    </script>
</body>
</html> 